package com.itheima.health;

import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class testLastDay {

    /*@Test
    public void test() {
        //Date date = new Date("2018-08-" + 01);
        //System.out.println(date);
        Date date1 = new Date(2019, 12, 0);
        System.out.println(date1);//Wed Dec 31 00:00:00 CST 3919
        System.out.println(date1.getDate());//31
        Date date = new Date();
        System.out.println(date);//Sun Dec 08 14:59:00 CST 2019
        date.setDate(0);
        System.out.println(date);//Sat Nov 30 14:59:00 CST 2019
        System.out.println(date.getDate());//30
    }*/

    @Test
    public void getCurrentMonthLastDay() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cale = Calendar.getInstance();
        System.out.println(cale.getTime());//Sun Dec 08 15:07:14 CST 2019
        cale.add(Calendar.MONTH, 1);
        System.out.println(cale.getTime());//Wed Jan 08 15:07:14 CST 2020
        cale.set(Calendar.DAY_OF_MONTH, 0);
        System.out.println(cale.getTime());//Tue Dec 31 15:07:14 CST 2019
        String s = format.format(cale.getTime());
        System.out.println(s);//2019-12-31
        int i = cale.getTime().getDate();
        System.out.println(i);//31
    }

    public static void main(String[] args) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        int last = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        System.out.println(last);
    }
}
